package cn.dnui_wwt524.dnuifood_16110100524.model;

import cn.dnui_wwt524.dnuifood_16110100524.bean.ResultBean;
import cn.dnui_wwt524.dnuifood_16110100524.bean.UserBean;
import cn.dnui_wwt524.dnuifood_16110100524.iface.UserIface;
import cn.dnui_wwt524.dnuifood_16110100524.listener.OnRetrofitListener;
import cn.dnui_wwt524.dnuifood_16110100524.service.ShopService;
import cn.dnui_wwt524.dnuifood_16110100524.service.UserService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserModel extends BaseModel implements UserIface {
 //   private Retrofit retrofit;
    private UserService service;
//    private String BaseUrl = "http://172.24.10.175:8080/foodService/";
//    public UserModel(){
//        retrofit = new Retrofit.Builder().baseUrl(BaseUrl).addConverterFactory(GsonConverterFactory.create()).build();
//        service = retrofit.create(UserService.class);
//    }
public UserModel(){
    super();
    service = retrofit.create(UserService.class);
}
    @Override
    public void login(String username, String userpass, final OnRetrofitListener listener) {
        Call<UserBean> call = service.doLogin(username,userpass);
        service =retrofit.create(UserService.class);
        bindCallBack(call,listener,Constants.USERLOGIN);
//        call.enqueue(new Callback<UserBean>() {
//            @Override
//            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
//
//                if (response.body()!=null)
//                    listener.onSuccess(response.body());
//                else
//                    listener.onFailure("解析有误！");
//            }
//
//            @Override
//            public void onFailure(Call<UserBean> call, Throwable t) {
//                listener.onFailure("联网异常");
//
//            }
//
//
//        });
    }

    @Override
    public void reg(String username, String userpass, String mobilenum, String address, String comment, final OnRetrofitListener listener) {
        service = retrofit.create(UserService.class);
        Call<ResultBean> call;
        call =service.doRegister(username,userpass,mobilenum,address,comment);
        bindCallBack(call,listener,Constants.USERREGISTER);
 //       Call<ResultBean> call = service.doRegister(username,userpass,mobilenum,address,comment);
//        call.enqueue(new Callback<ResultBean>() {
//            @Override
//            public void onResponse(Call<ResultBean> call, Response<ResultBean> response) {
//                if (response.body()!=null)
//                    listener.onSuccess(response.body());
//                    else
//                    listener.onFailure("解析有误");
//
//            }
//
//            @Override
//            public void onFailure(Call<ResultBean> call, Throwable t) {
//                listener.onFailure("联网异常");
//            }
//        });
   }
    public class Constants{
        public final static String BASE_URL="http://172.24.10.175:8080/foodService/";
        public final static int USERLOGIN=1;
        public final static int USERREGISTER=2;
        public final static int GETALLSHOPS=3;
    }
}
